{% load markup %}
{% block script %}
<script type="text/javascript">
$(document).ready(function() {
    $(".dataset_metadata_toggle").toggle(
    function(){
        $(this).text("[Show]");
        var href= $(this).attr("href");
        $(href).hide();
    },
    function(){
        $(this).text("[Hide]");
        var href= $(this).attr("href");
        $(href).show();
    }
    );
    $(".dataset_metadata_toggle").click();
});

</script>

<script type="text/javascript" charset="utf-8">
    $(".experiment_metadata_toggle").text("[Show]");
    $(".experiment_metadata_toggle").next().hide();
    var loadingHTML = "<img src='/site_media/images/ajax-loader.gif'/>";

    // metadata text / ajax toggle

    $(document).ready(function(){

        $(".experiment_metadata_toggle").live('click', function(e){
            e.preventDefault();

            if($(this).text() == "[Show]")
            {

                $(this).text("[Hide]");
                var href= $(this).attr("href");

                $(this).next().html(loadingHTML + "</br>");
                $(this).next().load(href);
                $(this).next().show();
            }
            else
            {
                $(this).text("[Show]");
                var href= $(this).attr("href");
                $(this).next().hide();
            }
            return false;
        });
    });

</script>
{% endblock %}

<div id="experiment_description">

  <p>
    <strong>Authors: </strong><br/>
    {% for author in authors %}
      {{ author.author }}{% if not forloop.last %},{% endif %}
    {% endfor %}
  </p>

  <p>
    <strong>Abstract: </strong>
    <div class="abstract">
      {{ experiment.description|markdown:"safe" }}
    </div>
  </p>

  {% if experiment.handle %}
    <p>
      <strong>Persistent Handle:</strong>
      <a href="{{ handle }}/{{ experiment.handle }}">{{ experiment.handle }}</a><br/>
    </p>
  {% endif %}

  <p>
    <strong>Institution:</strong>
    {{experiment.institution_name}}<br/>
  </p>

  {% if experiment.start_time and experiment.end_time %}
    <p>
      <strong>Date:</strong>
      {{ experiment.start_time|date:"jS F Y H:i" }} - {{ experiment.end_time|date:"jS F Y H:i" }}<br/>
    </p>
  {% endif %}

  <p>
    {# {% if experiment.experimentparameterset_set.count %} #}
    <div class="experiment_md_container">
    <strong>Experiment Metadata:</strong>

    {% if has_write_permissions %}{% if not experiment.public %}
    <a href="{% url tardis.tardis_portal.views.add_experiment_par experiment.id %}"
     class="jqModalExpA{{experiment.id}}">[Add]</a>
    <script type="text/javascript">
    $('#jqmAlertExpA{{experiment.id}}').die();
    $('#jqmAlertExpA{{experiment.id}}').jqm({
      trigger: '.jqModalExpA{{experiment.id}}',
      ajax: '@href',
      target: '#jqmAlertContentexperimentA{{experiment.id}}',
      overlay: 0
      });
    </script>
    <div class="jqmAlert" id="jqmAlertExpA{{experiment.id}}">

        <div class="jqmAlertWindow">
            <div class="jqmAlertTitle clearfix">
            <h1>Add Parameters</h1><a href="#" class="jqmClose"><em>Close</em></a>
          </div>

          <div class="jqmAlertContent" id="jqmAlertContentexperimentA{{experiment.id}}">
          <p>Please wait... <img src="/site_media/images/busy.gif" alt="loading" /></p>
          </div>
        </div>
    </div>
    {% endif %}{% endif %}

    <a class="experiment_metadata_toggle" href="/ajax/experiment_metadata/{{experiment.id}}/">[Show]</a>
    <span class="experiment_metadata"></span>

    </div>
    {# {% endif %} #}
  </p>

  <p>
    <strong>Dataset Information:</strong>
    <div>
      <!-- <strong>Dataset Metadata: </strong>   -->
      <div class="dataset_information">
    <ul>
      <li><strong>Datasets:</strong> {{experiment.dataset_set.all.count}}</li>
      <li><strong>Files:</strong> {{datafiles.count}}</li>
      <li><strong>Size:</strong> {{size|filesizeformat}}</li>
    </ul>
      </div>
    </div>
  </p>

  <p>
    <strong>Experiment Last Updated:</strong>
    {{ experiment.update_time|date:"jS F Y H:i" }}<br/>
  </p>
  <div class="download_entire_experiment">
    {% for p in protocol %}
      <p>
    {% if p.0 %}
      <strong><a href="{{p.1}}">Download Entire Experiment ({{p.0|upper}})</a></strong><br/>
    {% else %}
      <strong><a href="{{p.1}}">Download Entire Experiment</a></strong><br/>
    {% endif %}
      </p>
    {% endfor %}
  </div>

  <p align="right">
    <br/>
    {% if owners %}
      <strong>Experiment Administrators </strong><br/>
      {% for owner in owners %}
        {% if owner.email %}
          <a href="mailto:{{owner.email}}">{{ owner.email}}</a>
        {% endif %}
        ({{ owner.username }})
        {% if not forloop.last %}
          <br/>
    {% endif %}
    </p>
    <p align="right">
    {% if experiment.public %}
        <em>This experiment is public.</em>
    {% endif %}
    {% if is_owner %}
    {% if not experiment.public %}
        <strong><a href="publish/">Publish Experiment</a></strong><br/>
    {% endif %}
    {% endif %}
      {% endfor %}
  </p>
{% endif %}

</div>
